package com.yds.ydsdatasetbackend.model.vo;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.*;
import com.yds.ydsdatasetbackend.model.dto.file.predict.FilePredictInputParams;
import com.yds.ydsdatasetbackend.model.dto.file.predict.FilePredictOutputParams;
import com.yds.ydsdatasetbackend.model.dto.file.predict.common.PredictResult;
import com.yds.ydsdatasetbackend.model.entity.FilePredict;
import com.yds.ydsdatasetbackend.model.entity.FileTrain;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 文件预测脱敏类
 */
@Data
public class FilePredictVO implements Serializable {
    /**
     * id
     */
    private Long id;

    /**
     * 对应的训练 id
     */
    private Long trainId;

    /**
     * 文件 id
     */
    private Long fileId;

    /**
     * 预测简介，用于描述预测的用途
     */
    private String introduction;

    /**
     * 训练状态：成功/等待/错误/运行
     */
    private String predictStatus;

    /**
     * 参数List列表
     */
    private List<FilePredictInputParams> predictParams;

    /**
     * 预测结果（JSON格式）
     */
    private PredictResult predictResult;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 训练信息
     */
    private FileTrainVO  fileTrain;

    /**
     * 封装类转对象
     */
    public static FilePredict voToObj(FilePredictVO filePredictVO) {
        if (filePredictVO == null) {
            return null;
        }
        FilePredict filePredict = new FilePredict();
        BeanUtils.copyProperties(filePredictVO, filePredict);
        // 类型不同，需要转换
        filePredict.setPredictParams(JSONUtil.toJsonStr(filePredictVO.getPredictParams()));
        return filePredict;
    }

    /**
     * 对象转封装类
     */
    public static FilePredictVO objToVo(FilePredict filePredict) {
        if (filePredict == null) {
            return null;
        }
        FilePredictVO filePredictVO = new FilePredictVO();
        BeanUtils.copyProperties(filePredict, filePredictVO);
        // 类型不同，需要转换
        filePredictVO.setPredictResult(JSONUtil.toBean(filePredict.getPredictResult(), PredictResult.class));
        filePredictVO.setPredictParams(JSONUtil.toList(filePredict.getPredictParams(), FilePredictInputParams.class));
        return filePredictVO;
    }

    private static final long serialVersionUID = 1L;
}